package cn.ctodb.notebook.wxapp.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import javax.validation.constraints.*;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import java.util.Objects;

/**
 * A Message.
 */
@Entity
@Table(name = "message")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Message implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Size(max = 1000)
    @Column(name = "content", length = 1000)
    private String content;

    @Column(name = "address")
    private String address;

    @Column(name = "jhi_open")
    private Boolean open;

    @OneToMany(mappedBy = "message")
    @JsonIgnore
    @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
    private Set<Pic> pics = new HashSet<>();

    @ManyToOne
    private WxUser user;

    // jhipster-needle-entity-add-field - JHipster will add fields here, do not remove
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getContent() {
        return content;
    }

    public Message content(String content) {
        this.content = content;
        return this;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getAddress() {
        return address;
    }

    public Message address(String address) {
        this.address = address;
        return this;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Boolean isOpen() {
        return open;
    }

    public Message open(Boolean open) {
        this.open = open;
        return this;
    }

    public void setOpen(Boolean open) {
        this.open = open;
    }

    public Set<Pic> getPics() {
        return pics;
    }

    public Message pics(Set<Pic> pics) {
        this.pics = pics;
        return this;
    }

    public Message addPic(Pic pic) {
        this.pics.add(pic);
        pic.setMessage(this);
        return this;
    }

    public Message removePic(Pic pic) {
        this.pics.remove(pic);
        pic.setMessage(null);
        return this;
    }

    public void setPics(Set<Pic> pics) {
        this.pics = pics;
    }

    public WxUser getUser() {
        return user;
    }

    public Message user(WxUser wxUser) {
        this.user = wxUser;
        return this;
    }

    public void setUser(WxUser wxUser) {
        this.user = wxUser;
    }
    // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here, do not remove

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Message message = (Message) o;
        if (message.getId() == null || getId() == null) {
            return false;
        }
        return Objects.equals(getId(), message.getId());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getId());
    }

    @Override
    public String toString() {
        return "Message{" +
            "id=" + getId() +
            ", content='" + getContent() + "'" +
            ", address='" + getAddress() + "'" +
            ", open='" + isOpen() + "'" +
            "}";
    }
}
